import {
  Loading
} from 'element-ui'

let loadingInstance
let loadingCount = 0

export const showLoading = () => {
  if (loadingCount === 0) {
    const options = {
      lock: true,
      text: '加载中...',
      // target: document.querySelector('.loading-area'),
      // spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.15)',
      customClass: 'loading-main'
    }
    loadingInstance = Loading.service(options)
    loadingCount += 1
  }
}

export const closeLoading = () => {
  if (loadingCount <= 0) {
    return
  }
  loadingCount -= 1
  if (loadingCount === 0) {
    loadingInstance.close()
  }
}